package com.yanqu.road.server.cmd.activity.apprentice;

import com.yanqu.road.entity.activity.apprentice.data.ApprenticeUserData;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ApprenticeProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.apprentice.CrossApprenticeActivity;
import com.yanqu.road.server.manager.activity.apprentice.CrossApprenticeMgr;
import com.yanqu.road.server.manager.activity.apprentice.pb.ApprenticePb;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_APPRENTICE_AFTER_LOGIN, desc = "爱徒养成-登录后处理")
public class CrossApprenticeAfterLoginCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ApprenticeProto.ApprenticeAfterLoginCrossReqMsg reqMsg = ApprenticeProto.ApprenticeAfterLoginCrossReqMsg.parseFrom(packet.getBytes());
        CrossApprenticeActivity activity = CrossApprenticeMgr.getActivity(reqMsg.getActivityId());
        if (activity != null) {
            ApprenticeUserData userData = activity.getUserData(packet.getPlayerId());
            if (userData != null) {
                activity.syncUserData(packet.getPlayerId());
                //跨服返回
                ApprenticeProto.ApprenticeAfterLoginCrossRespMsg.Builder respMsg = ApprenticeProto.ApprenticeAfterLoginCrossRespMsg.newBuilder();
                respMsg.setActivityId(reqMsg.getActivityId());
                respMsg.setUserData(ApprenticePb.buildUserData(userData, activity.getCanSelectProjectNum(userData)));
                MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_APPRENTICE_AFTER_LOGIN_FROM_CROSS, respMsg));
            }
        }
    }

    @Override
    public void sendData() {

    }
}
